{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Layered Histogram\n",
    "=================\n",
    "This example shows how to use opacity to make a layered histogram in Altair.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import pandas as pd\n",
    "import altair as alt\n",
    "alt.data_transformers.enable('json')\n",
    "import numpy as np\n",
    "np.random.seed(42)\n",
    "\n",
    "# Generating Data\n",
    "df = pd.DataFrame({'Trial A': np.random.normal(0, 0.8, 1000),\n",
    "                   'Trial B': np.random.normal(-2, 1, 1000),\n",
    "                   'Trial C': np.random.normal(3, 2, 1000)})\n",
    "\n",
    "# Tidying Data\n",
    "df = pd.melt(df, id_vars=df.index.name,\n",
    "             value_vars=df.columns,\n",
    "             var_name='Experiment',\n",
    "             value_name='Measurement')\n",
    "\n",
    "alt.Chart(df).mark_area(\n",
    "    opacity=0.3,\n",
    "    interpolate='step'\n",
    ").encode(\n",
    "    alt.X('Measurement', bin=alt.Bin(maxbins=100)),\n",
    "    alt.Y('count()', stack=None),\n",
    "    alt.Color(\n",
    "        'Experiment',\n",
    "        scale=alt.Scale(range=['#0000ff', '#008000', '#ff0000'])\n",
    "    )\n",
    ")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "env": {},
   "interrupt_mode": "signal",
   "language": "python",
   "metadata": {},
   "name": "python3"
  },
  "language": "python"
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
